
package cn.xabad.commons.plist;
import java.lang.String;

public class Data extends PListObject implements
		IPListSimpleObject<String> {

	protected Stringer dataStringer;
	protected byte[] rawData;

	
	private static final long serialVersionUID = -3101592260075687323L;

	public Data() {
		setType(PListObjectType.DATA);
		dataStringer = new Stringer();
	}

	
	@Override
	public String getValue() {
		return getValue(true);
	}

	
	public String getValue(boolean decode) {
		dataStringer.newBuilder();
		if (decode) {
			return dataStringer.getBuilder()
					.append(new String(Base64.decodeFast(rawData)))
					.toString();
		} else {
			return dataStringer.getBuilder().append(rawData).toString();
		}
	}

	
	@Override
	public void setValue(String val) {
		setValue(val, true);
	}

	
	public void setValue(String val, boolean encoded) {
		if (!encoded) {
			rawData = Base64.encodeToByte(val.getBytes(), false);
		} else {
			rawData = val.getBytes();
		}
	}

	
	public void setValue(byte[] val, boolean encoded) {
		if (!encoded) {
			rawData = Base64.encodeToByte(val, false);
		} else {
			rawData = val;
		}
	}

}
